/*******************************************************************************************************

Table A13: Difference-in-differences estimates by type of sender


*******************************************************************************************************/

*Set directory path
cd "C:\Users\tsa23\Documents\petitions\replication files"

clear all

*read in our main dataset
use dta/did_rep.dta


*Elminate contrituencies which are not part of case G
drop if ID == 45 //University of Cambridge
drop if ID == 191 //University of Oxford
keep if new == 1 | drummond == .

drop if year==1830 | year==1831 | year==1832

gen treatgroup = 0
replace treatgroup =  1 if new==1 

gen treatinter = treatperiod*treatgroup

label var type1 "Religion"
label var type2 "Citizens"
label var type3 "Societies"
label var type4 "Local government"
label var type5 "Business"
label var type6 "Transport"
label var type7 "Others"


foreach n of numlist 1/7 {
gen temptype`n' = type`n'
replace temptype`n'=0 if type`n'==.
}


gen business = temptype6 + temptype5
replace business =. if business == 0
replace business = ln(business+1)

gen religious = temptype1 
replace religious =. if religious==0
replace religious = ln(religious+1)

gen societies =  temptype3  
replace societies =. if societies==0
replace societies = ln(societies+1)

gen individuals =  temptype2
replace individuals =. if individuals==0
replace individuals = ln(individuals+1)


gen local = temptype4  
replace local =. if local==0
replace local = ln(local+1)


collapse ln_petitions local business religious societies individuals treatgroup, by(ID treatperiod treatinter)

label var treatinter "T * A" 
label var treatgroup "T" 
label var treatperiod "A" 

label var societies "societies" /*Petitions from civic groups*/
label var business "Petitions from business groups"
label var individuals "Petitions from individual citizens"
label var religious "Petitions from religious groups"
label var local "Petitions from local government bodies"


reg societies treatinter treatgroup treatperiod  , cl(ID)
* this makes sure that we only use towns that got information before and after. The point estimates are the same but the stds are a bit different.
gen ok=e(sample)
egen sumok=total(ok), by(ID)
su sumok, meanonly
gen allok=(sumok==r(max))
reg societies treatinter treatgroup treatperiod  if allok==1, cl(ID)
outreg2 treatgroup treatperiod  treatinter using results\tableA13, replace addt(Constituencies, N/2, Treatment, G)  asterisk(coef) auto(2) label se  symbol(**,*,+) ctitle(`n') tex(frag) keep(treatgroup treatperiod  treatinter ) nocons
drop ok sumok allok



foreach n of varlist  business individuals religious local {
reg `n' treatgroup treatperiod  treatinter , cl(ID)
* this makes sure that we only use towns that got information before and after. The point estimates are the same but the stds are a bit different.
 gen ok=e(sample)
egen sumok=total(ok), by(ID)
su sumok, meanonly
gen allok=(sumok==r(max))
reg `n' treatinter treatgroup treatperiod  if allok==1, cl(ID)
outreg2 treatgroup treatperiod  treatinter  using results\tableA13, append addt(Constituencies, N/2, Treatment, G)  asterisk(coef) auto(2) label se  symbol(**,*,+) ctitle(`n') tex(frag) keep(treatgroup treatperiod  treatinter  ) nocons

gen allok`n' = allok
drop ok sumok allok

}



